package com.carpark.ejb.DAO;

import Validator.Validator;
import com.carpark.ejb.Model.AccountingdataModel;
import com.carpark.ejb.Model.CarsModel;
import com.carpark.ejb.Model.ClientsModel;
import com.carpark.ejb.Model.EmployeesModel;
import com.carpark.ejb.Model.ParkingpassesModel;
import com.carpark.ejb.Model.ParkingspacesModel;
import com.carpark.ejb.Model.ParksModel;
import com.carpark.ejb.Model.PassesrecordsModel;
import com.carpark.ejb.Model.PaymentsModel;
import com.carpark.ejb.Model.ReceivablesModel;
import com.carpark.ejb.Model.ServicesModel;
import com.carpark.ejb.Model.TarrifsModel;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.ejb.Stateless;

@Stateless
public class DaoImpl implements DAO {

    private EmployeeDAO employeeInstance;
    private ClientDAO clientInstance;
    private CarDAO carInstance;
    private TarrifsDAO tarrifInstance;
    private ParkingspacesDAO parkingSpaceInstance;
    private AccountingdataDAO accountingDataInstnace;
    private ServicesDAO serviceInstance;
    private ReceivablesDAO receivableInstance;
    private PaymentsDAO paymentInstnace;
    private ParksDAO parkInstance;
    private ParkingpassesDAO passInstance;
    private PassesrecordDAO passRecordsInstance;
    private EntityManager entityManager;

    public DaoImpl() {
        employeeInstance = new EmployeeDAOImpl();
        clientInstance = new ClientDAOImpl();
        carInstance = new CarDAOImpl();
        parkingSpaceInstance = new ParkingspacesDAOImpl();
        tarrifInstance = new TarrifsDAOImpl();
        accountingDataInstnace = new AccountingdataDAOImpl();
        serviceInstance = new ServicesDAOImpl();
        receivableInstance = new ReceivablesDAOImpl();
        paymentInstnace = new PaymentsDAOImpl();
        parkInstance = new ParksDAOImpl();
        passInstance = new ParkingpassesDAOImpl();
        passRecordsInstance = new PassesrecordDAOImpl();

        EntityManagerFactory factory = Persistence.createEntityManagerFactory("persistenceUnit");
        entityManager = factory.createEntityManager();
    }

    @Override
    public EmployeesModel addEmployee(EmployeesModel employee) {
        if (Validator.checkEmloyee(employee)) {

            employeeInstance.addEmployee(employee);
            return employee;

        }
        return null;
    }

    @Override
    public EmployeesModel updateEmployee(EmployeesModel employee) {
        if (Validator.checkEmloyee(employee)) {
            employeeInstance.updateEmployee(employee);
            return employee;
        }
        return null;
    }

    @Override
    public List<EmployeesModel> getAllEmployees() {
        return employeeInstance.getAllEmployees();
    }

    @Override
    public EmployeesModel deleteEmployee(EmployeesModel employee) {
        if (Validator.checkEmloyee(employee)) {
            employeeInstance.removeEmployeeById(employee.getEmployeeId());
            return employee;
        }
        return null;
    }

    @Override
    public ClientsModel addClient(ClientsModel client) {
        if (Validator.checkClient(client)) {

            clientInstance.addClient(client);
            return client;

        }
        return null;
    }

    @Override
    public ClientsModel updateClient(ClientsModel client) {
        if (Validator.checkClient(client)) {
            clientInstance.updateClient(client);
            return client;
        }
        return null;
    }

    @Override
    public ClientsModel deleteClient(ClientsModel client) {
        if (Validator.checkClient(client)) {
            clientInstance.removeClientById(client.getClientId());
            return client;
        }
        return null;
    }

    @Override
    public CarsModel addCar(CarsModel car) {
        if (Validator.checkCar(car)) {
            return carInstance.addCar(car);
        }
        return null;
    }

    @Override
    public CarsModel updateCar(CarsModel car) {
        if (Validator.checkCar(car)) {
            carInstance.updateCar(car);
            return car;
        }
        return null;
    }

    @Override
    public CarsModel deleteCar(CarsModel car) {
        if (Validator.checkCar(car)) {
            carInstance.removeCar(car.getCarId());
            return car;
        }
        return null;
    }

    @Override
    public List<ParkingpassesModel> getParkingPassBySpaceId(ParkingspacesModel space) {
        return this.passInstance.getParkingPassBySpaceId(space);
    }

    @Override
    public ParkingspacesModel addParkingSpace(ParkingspacesModel parkingSpace) {
        if (Validator.checkParkingSpace(parkingSpace)) {
            parkingSpaceInstance.addSpace(parkingSpace);
            return parkingSpace;
        }
        return null;
    }

    @Override
    public ParkingspacesModel updateParkingSpace(ParkingspacesModel parkingSpace) {
        if (Validator.checkParkingSpace(parkingSpace)) {
            parkingSpaceInstance.updateSpace(parkingSpace);
            return parkingSpace;
        }
        return null;
    }

    @Override
    public boolean synchronizeParkingSpacesWithConfiguration(List<ParkingspacesModel> spacesToUpdate) {
        return parkingSpaceInstance.synchronizeParkingSpacesWithConfiguration(spacesToUpdate);
    }

    @Override
    public ParkingspacesModel deleteParkingSpace(ParkingspacesModel parkingSpace) {
        if (Validator.checkParkingSpace(parkingSpace)) {
            parkingSpaceInstance.removeSpace(parkingSpace);
            return parkingSpace;
        }
        return null;
    }

    @Override
    public TarrifsModel addTarrif(TarrifsModel tarrif) {
        if (Validator.checkTarrif(tarrif)) {
            tarrifInstance.addTarrif(tarrif);
            return tarrif;
        }
        return null;
    }

    @Override
    public TarrifsModel updateTarrif(TarrifsModel tarrif) {
        if (Validator.checkTarrif(tarrif)) {
            tarrifInstance.updateTarrif(tarrif);
            return tarrif;
        }
        return null;
    }

    @Override
    public TarrifsModel deleteTarrifs(TarrifsModel tarrif) {
        if (Validator.checkTarrif(tarrif)) {
            tarrifInstance.removeTarrif(tarrif);
            return tarrif;
        }
        return null;
    }

    @Override
    public AccountingdataModel addAccountingdata(AccountingdataModel accountingData) {
        if (Validator.checkAccountingData(accountingData)) {
            accountingDataInstnace.addAccountingData(accountingData);
            return accountingData;
        }
        return null;
    }

    @Override
    public AccountingdataModel updateAccountingdata(AccountingdataModel accountingData) {
        if (Validator.checkAccountingData(accountingData)) {
            accountingDataInstnace.addAccountingData(accountingData);
            return accountingData;
        }
        return null;
    }

    @Override
    public AccountingdataModel deleteAccountingdata(AccountingdataModel accountingData) {
        if (Validator.checkAccountingData(accountingData)) {
            accountingDataInstnace.removeAccountingData(accountingData.getAccountingDataId());
            return accountingData;
        }
        return null;
    }

    @Override
    public ServicesModel addService(ServicesModel service) {
        if (Validator.checkServices(service)) {
            serviceInstance.addService(service);
            return service;
        }
        return null;
    }

    @Override
    public ServicesModel updateService(ServicesModel service) {
        if (Validator.checkServices(service)) {
            serviceInstance.updateService(service);
            return service;
        }
        return null;
    }

    @Override
    public ServicesModel addService(ServicesModel service, ClientsModel client, EmployeesModel epEmployees) {
        if (Validator.checkServices(service) && Validator.checkClient(client) && Validator.checkEmloyee(epEmployees)) {
            entityManager.getTransaction().begin();
            entityManager.persist(client);
            entityManager.flush();
            entityManager.refresh(client);
            entityManager.persist(epEmployees);

            entityManager.flush();

            service.setClientId(client);
            entityManager.refresh(epEmployees);
            entityManager.persist(epEmployees);
            service.setEployeeId(epEmployees);

            entityManager.persist(service);

            entityManager.getTransaction().commit();

            return service;
        }
        return null;
    }

    @Override
    public ServicesModel deleteService(ServicesModel service) {
        if (Validator.checkServices(service)) {
            serviceInstance.removeService(service.getServiceId());
            return service;
        }
        return null;
    }

    @Override
    public ReceivablesModel addReceivable(ReceivablesModel receivable) {
        if (Validator.checkReceivables(receivable)) {
            receivableInstance.addReceivable(receivable);
            return receivable;
        }
        return null;
    }

    @Override
    public ReceivablesModel updateReceivable(ReceivablesModel receivable) {
        if (Validator.checkReceivables(receivable)) {

            receivableInstance.updateReceivable(receivable);
            return receivable;
        }
        return null;
    }

    @Override
    public ReceivablesModel addReceivable(ReceivablesModel receivable, ParkingpassesModel parkingPass) {
        if (Validator.checkReceivables(receivable) && Validator.checkPasses(parkingPass)) {
            entityManager.getTransaction().begin();
            entityManager.persist(parkingPass);
            entityManager.flush();
            entityManager.refresh(parkingPass);
            entityManager.persist(parkingPass);
            receivable.setParkingPassId(parkingPass);
            entityManager.persist(receivable);
            entityManager.getTransaction().commit();

            return receivable;
        }
        return null;
    }

    @Override
    public ReceivablesModel updateReceivable(ReceivablesModel receivable, ParkingpassesModel parkingPass) {
        if (Validator.checkReceivables(receivable) && Validator.checkPasses(parkingPass)) {
            entityManager.getTransaction().begin();
            entityManager.persist(parkingPass);
            entityManager.persist(receivable);
            entityManager.getTransaction().commit();

            return receivable;
        }
        return null;
    }

    @Override
    public ReceivablesModel deleteReceivable(ReceivablesModel receivable) {
        if (Validator.checkReceivables(receivable)) {

            receivableInstance.removeReceivable(receivable.getReceivableId());
            return receivable;

        }
        return null;
    }

    @Override
    public PaymentsModel addPayment(PaymentsModel payment) {
        if (Validator.checkPayments(payment)) {

            paymentInstnace.addPayment(payment);
            return payment;

        }
        return null;
    }

    @Override
    public PaymentsModel addPayment(PaymentsModel payment, ReceivablesModel receivable) {
        if (Validator.checkPayments(payment) && Validator.checkReceivables(receivable)) {
            entityManager.getTransaction().begin();

            entityManager.persist(receivable);
            entityManager.flush();
            entityManager.refresh(receivable);
            entityManager.persist(receivable);

            payment.setReceivableId(receivable);
            entityManager.persist(payment);
            entityManager.getTransaction().commit();

            return payment;
        }
        return null;
    }

    @Override
    public PaymentsModel updatePayment(PaymentsModel payment) {
        if (Validator.checkPayments(payment)) {

            paymentInstnace.updatePayment(payment);
            return payment;

        }
        return null;
    }

    @Override
    public PaymentsModel updatePayment(PaymentsModel payment, ReceivablesModel receivable) {
        if (Validator.checkPayments(payment) && Validator.checkReceivables(receivable)) {
            entityManager.getTransaction().begin();

            entityManager.persist(receivable);
            entityManager.persist(payment);
            entityManager.getTransaction().commit();
            return payment;
        }
        return null;
    }

    @Override
    public PaymentsModel deletePayment(PaymentsModel payment) {
        if (Validator.checkPayments(payment)) {
            paymentInstnace.removePayment(payment.getPaymentId());
            return payment;

        }
        return null;
    }

    @Override
    public ParksModel addPark(ParksModel park) {
        if (Validator.checkPark(park)) {
            parkInstance.addPark(park);
            return park;
        }
        return null;
    }

    @Override
    public ParksModel addPark(ParksModel park, ParkingpassesModel parkingPass) {
        if (Validator.checkPark(park) && Validator.checkPasses(parkingPass)) {
            entityManager.getTransaction().begin();

            entityManager.persist(parkingPass);
            entityManager.flush();
            entityManager.refresh(parkingPass);

            park.setParkingPassId(parkingPass);

            entityManager.persist(park);

            entityManager.getTransaction().commit();

            return park;
        }
        return null;
    }

    @Override
    public ParksModel updatePark(ParksModel park) {
        if (Validator.checkPark(park)) {
            parkInstance.updatePark(park);
            return park;
        }
        return null;
    }

    @Override
    public ParksModel updatePark(ParksModel park, ParkingpassesModel parkingPass) {
        if (Validator.checkPark(park) && Validator.checkPasses(parkingPass)) {
            entityManager.getTransaction().begin();

            entityManager.persist(parkingPass);
            entityManager.flush();
            entityManager.refresh(parkingPass);

            park.setParkingPassId(parkingPass);

            entityManager.persist(park);

            entityManager.getTransaction().commit();

            return park;
        }
        return null;
    }

    @Override
    public ParksModel deletePark(ParksModel park) {
        if (Validator.checkPark(park)) {
            parkInstance.removePark(park.getParkId());
            return park;
        }
        return null;
    }

    @Override
    public ParkingpassesModel addPass(ParkingpassesModel pass) {
        if (Validator.checkPasses(pass)) {
            passInstance.addPass(pass);
            return pass;

        }
        return null;
    }

    @Override
    public ParkingpassesModel addPass(ParkingpassesModel pass, CarsModel car) {
        if (Validator.checkPasses(pass) && Validator.checkCar(car)) {
            entityManager.getTransaction().begin();

            entityManager.persist(car);
            entityManager.flush();
            entityManager.refresh(car);

            pass.setCarId(car);

            entityManager.persist(pass);

            entityManager.getTransaction().commit();

            return pass;
        }
        return null;
    }

    @Override
    public ParkingpassesModel addPass(ParkingpassesModel pass, TarrifsModel tarrif) {
        if (Validator.checkPasses(pass) && Validator.checkTarrif(tarrif)) {
            entityManager.getTransaction().begin();

            entityManager.persist(tarrif);
            entityManager.flush();
            entityManager.refresh(tarrif);

            pass.setTarrif(tarrif);
            entityManager.persist(pass);

            entityManager.getTransaction().commit();

            return pass;
        }
        return null;
    }

    @Override
    public ParkingpassesModel addPass(ParkingpassesModel pass, ParkingspacesModel parkingSpace) {
        if (Validator.checkPasses(pass) && Validator.checkParkingSpace(parkingSpace)) {
            entityManager.getTransaction().begin();

            entityManager.persist(parkingSpace);
            entityManager.flush();
            entityManager.refresh(parkingSpace);

            pass.setNumberId(parkingSpace);

            entityManager.persist(pass);

            entityManager.getTransaction().commit();

            return pass;

        }
        return null;
    }

    @Override
    public ParkingpassesModel addPass(ParkingpassesModel pass, CarsModel car, TarrifsModel tarrif) {
        if (Validator.checkPasses(pass) && Validator.checkCar(car) && Validator.checkTarrif(tarrif)) {
            entityManager.getTransaction().begin();

            entityManager.persist(tarrif);
            entityManager.flush();
            entityManager.refresh(tarrif);

            entityManager.persist(car);
            entityManager.flush();
            entityManager.refresh(car);

            pass.setCarId(car);

            pass.setTarrif(tarrif);
            entityManager.persist(pass);

            entityManager.getTransaction().commit();

            return pass;
        }
        return null;
    }

    @Override
    public ParkingpassesModel addPass(ParkingpassesModel pass, CarsModel car, ParkingspacesModel parkingSpace) {
        if (Validator.checkPasses(pass) && Validator.checkCar(car) && Validator.checkParkingSpace(parkingSpace)) {
            entityManager.getTransaction().begin();

            entityManager.persist(parkingSpace);
            entityManager.flush();
            entityManager.refresh(parkingSpace);

            entityManager.persist(car);
            entityManager.flush();
            entityManager.refresh(car);

            pass.setCarId(car);
            pass.setNumberId(parkingSpace);

            entityManager.persist(pass);

            entityManager.getTransaction().commit();

            return pass;
        }
        return null;
    }

    @Override
    public ParkingpassesModel addPass(ParkingpassesModel pass, CarsModel car, ParkingspacesModel parkingSpace, TarrifsModel tarrif) {
        if (Validator.checkPasses(pass) && Validator.checkCar(car) && Validator.checkParkingSpace(parkingSpace) && Validator.checkTarrif(tarrif)) {

            entityManager.getTransaction().begin();

            entityManager.persist(tarrif);
            entityManager.flush();
            entityManager.refresh(tarrif);

            entityManager.persist(parkingSpace);
            entityManager.flush();
            entityManager.refresh(parkingSpace);

            entityManager.persist(car);
            entityManager.flush();
            entityManager.refresh(car);
            entityManager.persist(car);

            pass.setCarId(car);
            pass.setNumberId(parkingSpace);
            pass.setTarrif(tarrif);
            entityManager.persist(pass);

            entityManager.getTransaction().commit();

            return pass;
        }
        return null;
    }

    @Override
    public ParkingpassesModel updatePass(ParkingpassesModel pass) {
        if (Validator.checkPasses(pass)) {
            passInstance.updatePass(pass);
            return pass;
        }
        return null;
    }

    @Override
    public ParkingpassesModel updatePass(ParkingpassesModel pass, CarsModel car) {
        if (Validator.checkPasses(pass) && Validator.checkCar(car)) {
            entityManager.getTransaction().begin();

            entityManager.persist(car);
            entityManager.flush();
            entityManager.refresh(car);

            pass.setCarId(car);

            entityManager.persist(pass);

            entityManager.getTransaction().commit();

            return pass;

        }
        return null;
    }

    @Override
    public ParkingpassesModel updatePass(ParkingpassesModel pass, TarrifsModel tarrif) {
        if (Validator.checkPasses(pass) && Validator.checkTarrif(tarrif)) {
            entityManager.getTransaction().begin();

            entityManager.persist(tarrif);
            entityManager.flush();
            entityManager.refresh(tarrif);

            pass.setTarrif(tarrif);
            entityManager.persist(pass);

            entityManager.getTransaction().commit();

            return pass;
        }
        return null;
    }

    @Override
    public ParkingpassesModel updatePass(ParkingpassesModel pass, ParkingspacesModel parkingSpace) {
        if (Validator.checkPasses(pass) && Validator.checkParkingSpace(parkingSpace)) {
            entityManager.getTransaction().begin();

            entityManager.persist(parkingSpace);
            entityManager.flush();
            entityManager.refresh(parkingSpace);

            pass.setNumberId(parkingSpace);

            entityManager.persist(pass);

            entityManager.getTransaction().commit();

            return pass;
        }
        return null;
    }

    @Override
    public ParkingpassesModel updatePass(ParkingpassesModel pass, CarsModel car, TarrifsModel tarrif) {
        if (Validator.checkPasses(pass) && Validator.checkCar(car) && Validator.checkTarrif(tarrif)) {
            entityManager.getTransaction().begin();
            entityManager.persist(tarrif);
            entityManager.persist(car);
            entityManager.persist(pass);
            entityManager.getTransaction().commit();
            return pass;
        }
        return null;
    }

    @Override
    public ParkingpassesModel updatePass(ParkingpassesModel pass, CarsModel car, ParkingspacesModel parkingSpace) {
        if (Validator.checkPasses(pass) && Validator.checkCar(car) && Validator.checkParkingSpace(parkingSpace)) {
            entityManager.getTransaction().begin();

            entityManager.persist(parkingSpace);
            entityManager.flush();
            entityManager.refresh(parkingSpace);

            entityManager.persist(car);
            entityManager.flush();
            entityManager.refresh(car);

            pass.setCarId(car);
            pass.setNumberId(parkingSpace);

            entityManager.persist(pass);

            entityManager.getTransaction().commit();

            return pass;
        }
        return null;
    }

    @Override
    public ParkingpassesModel updatePass(ParkingpassesModel pass, CarsModel car, ParkingspacesModel parkingSpace, TarrifsModel tarrif) {
        if (Validator.checkPasses(pass) && Validator.checkCar(car) && Validator.checkParkingSpace(parkingSpace) && Validator.checkTarrif(tarrif)) {

            entityManager.getTransaction().begin();

            entityManager.persist(tarrif);
            entityManager.flush();
            entityManager.refresh(tarrif);

            entityManager.persist(parkingSpace);
            entityManager.flush();
            entityManager.refresh(parkingSpace);

            entityManager.persist(car);
            entityManager.flush();
            entityManager.refresh(car);
            entityManager.persist(car);

            pass.setCarId(car);
            pass.setNumberId(parkingSpace);
            pass.setTarrif(tarrif);
            entityManager.persist(pass);

            entityManager.getTransaction().commit();

            return pass;
        }
        return null;
    }

    @Override
    public ParkingpassesModel deletePass(ParkingpassesModel pass) {
        if (Validator.checkPasses(pass)) {
            passInstance.detelePass(pass);
            return pass;
        }
        return null;
    }

    @Override
    public PassesrecordsModel addPassRecord(PassesrecordsModel passRecord) {
        if (Validator.checkPassesrecord(passRecord)) {
            passRecordsInstance.addPassesrecord(passRecord);
            return passRecord;

        }
        return null;
    }

    @Override
    public PassesrecordsModel addPassRecord(PassesrecordsModel passRecord, ClientsModel client) {
        if (Validator.checkPassesrecord(passRecord) && Validator.checkClient(client)) {
            entityManager.getTransaction().begin();

            entityManager.persist(client);
            entityManager.flush();
            entityManager.refresh(client);
            entityManager.persist(client);
            passRecord.setClientId(client);
            entityManager.persist(passRecord);
            entityManager.getTransaction().commit();

            return passRecord;
        }
        return null;
    }

    @Override
    public PassesrecordsModel addPassRecord(PassesrecordsModel passRecord, ParkingpassesModel parkingPass) {
        if (Validator.checkPassesrecord(passRecord) && Validator.checkPasses(parkingPass)) {
            entityManager.getTransaction().begin();

            entityManager.persist(parkingPass);
            entityManager.flush();
            entityManager.refresh(parkingPass);
            entityManager.persist(parkingPass);
            passRecord.setParkingPassId(parkingPass);
            entityManager.persist(passRecord);
            entityManager.getTransaction().commit();

            return passRecord;
        }
        return null;
    }

    @Override
    public PassesrecordsModel addPassRecord(PassesrecordsModel passRecord, AccountingdataModel accountingData) {
        if (Validator.checkPassesrecord(passRecord) && Validator.checkAccountingData(accountingData)) {
            entityManager.getTransaction().begin();

            entityManager.persist(accountingData);
            entityManager.flush();
            entityManager.refresh(accountingData);
            entityManager.persist(accountingData);

            passRecord.setAccountingDataId(accountingData);
            entityManager.persist(passRecord);
            entityManager.getTransaction().commit();

            return passRecord;
        }
        return null;
    }

    @Override
    public PassesrecordsModel addPassRecord(PassesrecordsModel passRecord, ClientsModel client, ParkingpassesModel parkingPass, AccountingdataModel accountingData) {
        if (Validator.checkPassesrecord(passRecord) && Validator.checkClient(client) && Validator.checkPasses(parkingPass) && Validator.checkAccountingData(accountingData)) {
            entityManager.getTransaction().begin();

            entityManager.persist(client);
            entityManager.flush();
            entityManager.refresh(client);

            entityManager.persist(parkingPass);
            entityManager.flush();
            entityManager.refresh(parkingPass);

            entityManager.persist(accountingData);
            entityManager.flush();
            entityManager.refresh(accountingData);

            passRecord.setAccountingDataId(accountingData);
            passRecord.setClientId(client);
            passRecord.setParkingPassId(parkingPass);

            entityManager.persist(passRecord);

            entityManager.getTransaction().commit();

            return passRecord;
        }
        return null;
    }

    @Override
    public PassesrecordsModel updatePassRecord(PassesrecordsModel passRecord) {
        if (Validator.checkPassesrecord(passRecord)) {
            passRecordsInstance.updatePassesrecord(passRecord);
            return passRecord;
        }
        return null;
    }

    @Override
    public PassesrecordsModel updatePassRecord(PassesrecordsModel passRecord, ClientsModel client) {
        if (Validator.checkPassesrecord(passRecord) && Validator.checkClient(client)) {
            entityManager.getTransaction().begin();

            entityManager.persist(client);
            entityManager.persist(passRecord);

            entityManager.getTransaction().commit();
            return passRecord;
        }
        return null;
    }

    @Override
    public PassesrecordsModel updatePassRecord(PassesrecordsModel passRecord, ParkingpassesModel parkingPass) {
        if (Validator.checkPassesrecord(passRecord) && Validator.checkPasses(parkingPass)) {
            entityManager.getTransaction().begin();

            entityManager.persist(parkingPass);
            entityManager.persist(passRecord);

            entityManager.getTransaction().commit();
            return passRecord;
        }
        return null;
    }

    @Override
    public PassesrecordsModel updatePassRecord(PassesrecordsModel passRecord, AccountingdataModel accountingData) {
        if (Validator.checkPassesrecord(passRecord) && Validator.checkAccountingData(accountingData)) {
            entityManager.getTransaction().begin();

            entityManager.persist(accountingData);
            entityManager.persist(passRecord);

            entityManager.getTransaction().commit();
            return passRecord;
        }
        return null;
    }

    @Override
    public PassesrecordsModel updatePassRecord(PassesrecordsModel passRecord, ClientsModel client, ParkingpassesModel parkingPass, AccountingdataModel accountingData) {
        if (Validator.checkPassesrecord(passRecord) && Validator.checkClient(client) && Validator.checkPasses(parkingPass) && Validator.checkAccountingData(accountingData)) {
            entityManager.getTransaction().begin();
            entityManager.persist(client);
            entityManager.persist(accountingData);
            entityManager.persist(parkingPass);
            entityManager.persist(passRecord);

            entityManager.getTransaction().commit();
            return passRecord;
        }
        return null;
    }

    @Override
    public PassesrecordsModel deletePassRecord(PassesrecordsModel passRecord) {
        if (Validator.checkPassesrecord(passRecord)) {
            passRecordsInstance.removePassesrecord(passRecord.getRecordId());
            return passRecord;
        }
        return null;
    }

    @Override
    public Collection<AccountingdataModel> getAccountingDataByName(String name) {
        return accountingDataInstnace.getAccountingDataByName(name);
    }

    @Override
    public Collection<AccountingdataModel> getAccountingDataByCity(String city) {
        return accountingDataInstnace.getAccountingDataByCity(city);
    }

    @Override
    public Collection<AccountingdataModel> getAccountingDataByZipCode(String zipCode) {
        return accountingDataInstnace.getAccountingDataByZipCode(zipCode);
    }

    @Override
    public Collection<AccountingdataModel> getAccountingDataByPayerType(String payerType) {
        return accountingDataInstnace.getAccountingDataByPayerType(payerType);
    }

    @Override
    public AccountingdataModel getAccountingDataById(Integer id) {
        return accountingDataInstnace.getAccountingDataById(id);
    }

    @Override
    public int getAccountingDataSize() {
        return accountingDataInstnace.getAccountingDataSize();
    }

    @Override
    public List<AccountingdataModel> getAllAccountingData() {
        return accountingDataInstnace.getAllAccountingData();
    }

    @Override
    public CarsModel getCarById(Integer id) {
        return carInstance.getCarById(id);
    }

    @Override
    public int getCarsSize() {
        return carInstance.getCarsSize();
    }

    @Override
    public EmployeesModel getEmployeeById(Integer id) {
        return employeeInstance.getEmployeeById(id);
    }

    @Override
    public int getEmployeesModelSize() {
        return employeeInstance.getEmployeesModelSize();
    }

    @Override
    public ClientsModel getClientById(Integer id) {
        return clientInstance.getClientById(id);
    }

    @Override
    public ClientsModel getClientByEmail(String mail) {
        return clientInstance.getClientByEmail(mail);
    }

    @Override
    public int getClientsModelSize() {
        return clientInstance.getClientsModelSize();
    }

    @Override
    public List<ParkingpassesModel> getAllParkingPasses() {
        return passInstance.getAllParkingPasses();
    }

    @Override
    public int getParkingPassesSize() {
        return passInstance.getParkingPassesSize();
    }

    @Override
    public ParkingpassesModel getParkingPassById(Integer id) {
        return passInstance.getParkingPassById(id);
    }

    @Override
    public List<ParkingpassesModel> getParkingPassesByDateIssue(Date dateIssue) {
        return passInstance.getParkingPassesByDateIssue(dateIssue);
    }

    @Override
    public List<ParkingpassesModel> getParkingPassesByExpirationDate(Date expirationDate) {
        return passInstance.getParkingPassesByExpirationDate(expirationDate);
    }

    @Override
    public List<ParkingpassesModel> getParkingPassesByPassType(String passType) {
        return passInstance.getParkingPassesByPassType(passType);
    }

    @Override
    public List<ParkingspacesModel> getAllParkingSpaces() {
        return parkingSpaceInstance.getAllParkingSpaces();
    }

    @Override
    public int getParkingSpacesSize() {
        return parkingSpaceInstance.getParkingSpacesSize();
    }

    @Override
    public ParkingspacesModel getParkingSpacesByNumber(Integer number) {
        return parkingSpaceInstance.getParkingSpacesByNumber(number);
    }

    @Override
    public List<ParkingspacesModel> getParkingSpacesByType(String type) {
        return parkingSpaceInstance.getParkingSpacesByType(type);
    }

    @Override
    public List<ParkingspacesModel> getParkingSpacesByStatus(String status) {
        return parkingSpaceInstance.getParkingSpacesByStatus(status);
    }

    @Override
    public int getParksSize() {
        return parkInstance.getParksSize();
    }

    @Override
    public ParksModel getParksById(Integer id) {
        return parkInstance.getParksById(id);
    }

    @Override
    public List<ParksModel> getParksByParkDate(Date parkDate) {
        return parkInstance.getParksByParkDate(parkDate);
    }

    @Override
    public List<ParksModel> getParksByType(String type) {
        return parkInstance.getParksByType(type);
    }

    @Override
    public List<PaymentsModel> getPaymentsByPaymentForm(String paymentForm) {
        return paymentInstnace.getPaymentsByPaymentForm(paymentForm);
    }

    @Override
    public List<PaymentsModel> getAllPayments() {
        return paymentInstnace.getAllPayments();
    }

    @Override
    public int getPaymentsSize() {
        return paymentInstnace.getPaymentsSize();
    }

    @Override
    public PaymentsModel getPaymentsById(Integer id) {
        return paymentInstnace.getPaymentsById(id);
    }

    @Override
    public List<PaymentsModel> getPaymentsByPaymentDate(Date paymentDate) {
        return paymentInstnace.getPaymentsByPaymentDate(paymentDate);
    }

    @Override
    public int getPassesrecordModelSize() {
        return passRecordsInstance.getPassesrecordModelSize();
    }

    @Override
    public List<PassesrecordsModel> getPassesrecordByAddingDate(Date addingDate) {
        return passRecordsInstance.getPassesrecordByAddingDate(addingDate);
    }

    @Override
    public List<PassesrecordsModel> getAllPassesRecords() {
        return passRecordsInstance.getAllPassesRecords();
    }

    @Override
    public PassesrecordsModel getPassesrecordById(Integer id) {
        return passRecordsInstance.getPassesrecordById(id);
    }

    @Override
    public int getTarrifsSize() {
        return tarrifInstance.getTarrifsSize();
    }

    @Override
    public List<TarrifsModel> getAllTarrifs() {
        return tarrifInstance.getAllTarrifs();
    }

    @Override
    public TarrifsModel getTarrifsById(Integer id) {
        return tarrifInstance.getTarrifsById(id);
    }

    @Override
    public List<TarrifsModel> getTarrifsByName(String name) {
        return tarrifInstance.getTarrifsByName(name);
    }

    @Override
    public List<TarrifsModel> getTarrifsByIssueDate(Date issueDate) {
        return tarrifInstance.getTarrifsByIssueDate(issueDate);
    }

    @Override
    public List<TarrifsModel> getTarrifsByEndDate(Date endDate) {
        return tarrifInstance.getTarrifsByEndDate(endDate);
    }

    @Override
    public List<TarrifsModel> getTarrifsByDurationTime(String durationTime) {
        return tarrifInstance.getTarrifsByDurationTime(durationTime);
    }

    @Override
    public List<TarrifsModel> getTarrifsByRank(Double rank) {
        return tarrifInstance.getTarrifsByRank(rank);
    }

    @Override
    public List<TarrifsModel> getTarrifsByCarType(String carType) {
        return tarrifInstance.getTarrifsByCarType(carType);
    }

    @Override
    public List<ServicesModel> getServicesAll() {
        return serviceInstance.getServicesAll();
    }

    @Override
    public List<ServicesModel> getServicesByModificationDate(Date modificationDate) {
        return serviceInstance.getServicesByModificationDate(modificationDate);
    }

    @Override
    public int getServicesSize() {
        return serviceInstance.getServicesSize();
    }

    @Override
    public List<ServicesModel> getServicesByClientId(Integer id) {
        return serviceInstance.getServicesByClientId(id);
    }

    @Override
    public ServicesModel getServicesByID(Integer Id) {
        return serviceInstance.getServicesByID(Id);
    }

    @Override
    public List<ReceivablesModel> getAllReceivable() {
        return receivableInstance.getAllReceivable();
    }

    @Override
    public int getReceivableSize() {
        return receivableInstance.getReceivableSize();
    }

    @Override
    public ReceivablesModel getReceivablesById(Integer id) {
        return receivableInstance.getReceivablesById(id);
    }

    @Override
    public List<ReceivablesModel> getReceivablesByAmount(Double amount) {
        return receivableInstance.getReceivablesByAmount(amount);
    }

    @Override
    public List<ReceivablesModel> getReceivablesByCreationDate(Date creationDate) {
        return receivableInstance.getReceivablesByCreationDate(creationDate);
    }

    @Override
    public List<ReceivablesModel> getReceivablesByPayDeadline(Date payDeadline) {
        return receivableInstance.getReceivablesByPayDeadline(payDeadline);
    }

    @Override
    public List<ParksModel> getAllParks() {
        return parkInstance.getAllParks();
    }

    @Override
    public List<CarsModel> getAllCars() {
        return carInstance.getAllCars();
    }

    @Override
    public List<ClientsModel> getAllClients() {
        return clientInstance.getAllClients();
    }

    @Override
    public List<ReceivablesModel> getReceivablesByClient(ClientsModel cl) {

        return receivableInstance.getReceivablesByClient(cl);
    }

    @Override
    public List<ServicesModel> getServicesByClient(ClientsModel cl) {
        return serviceInstance.getServicesByClient(cl);
    }

    @Override
    public List<ParksModel> getParksByClient(ClientsModel cl) {
        return parkInstance.getParksByClient(cl);
    }

    @Override
    public List<PaymentsModel> getPaymentsByClient(ClientsModel cl) {
        return paymentInstnace.getPaymentsByClient(cl);
    }

    @Override
    public List<ParkingpassesModel> getPassesByClient(ClientsModel cl) {

        return passRecordsInstance.getParkingPassesByClient(cl);
    }

    @Override
    public List<CarsModel> getCarsByClient(ClientsModel cl) {
        return carInstance.getCarsByClient(cl);
    }

    @Override
    public List<AccountingdataModel> getAccountingDataByClient(ClientsModel cl) {
        return passRecordsInstance.getAccountingDataByClient(cl);
    }

    @Override
    public List<ReceivablesModel> getPayedReceivables() {
        return paymentInstnace.getPayedReceivables();
    }

    @Override
    public List<ParkingspacesModel> getParkingSpacesForReservation(Date issue, Date end, String carType) {
        return parkingSpaceInstance.getParkingSpacesForReservation(issue, end, carType);
    }

    @Override
    public List<CarsModel> getCarsByClientAndType(ClientsModel cl, String type) {
        return carInstance.getCarsByClientAndType(cl, type);
    }

    @Override
    public AccountingdataModel getAccountingByPass(ParkingpassesModel pass) {
        return passRecordsInstance.getAccountingByPass(pass);
    }

    @Override
    public List<ParkingpassesModel> getPassesByAccounting(AccountingdataModel acc) {
        return passRecordsInstance.getParkingPassesByAccounting(acc);
    }

    @Override
    public List<ParksModel> getParksByClientAndType(ClientsModel cl, String type) {
        return parkInstance.getParksByClientAndType(cl, type);
    }

    @Override
    public AccountingdataModel updateAccData(AccountingdataModel accountingdataModel) {
        if (Validator.checkAccountingData(accountingdataModel)) {
            accountingDataInstnace.updateAccData(accountingdataModel);
            return accountingdataModel;
        }
        return null;
    }

    @Override
    public List<TarrifsModel> getTarrifsByCarTypeAndDT(String carType, String time) {
        return tarrifInstance.getTarrifsByCarTypeAndDT(carType, time);
    }

}
